/*
 *  Copyright 2010 UPF Telecos 4th group G.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package edu.upf.content;

import edu.upf.utils.Definitions;
import java.awt.Image;
import java.io.File;
import java.io.Serializable;
import javax.swing.ImageIcon;


/**
 * This class models an image with an id and a list of keywords
 * @author netjois
 */
public class ImageObject implements Serializable, Definitions, DescriptionContent{

    private String name;
    private String size;
    private String path;
    private String owner;
    private String popularity;
    private ImageIcon thumbnail;

    @Override
    public void setName(String n) {
        name = n;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setSize(String s) {
        size = s;
    }

    @Override
    public String getSize() {
        return size;
    }

    @Override
    public void setPath(String p) {
        path = p;
    }

    @Override
    public String getPath() {
        return path;
    }

    @Override
    public void setPopularity(String p) {
        popularity = p;
    }

    @Override
    public String getPopularity() {
        return popularity;
    }

    @Override
    public void setOwner(String owner) {
        this.owner = owner;
    }

    @Override
    public String getOwner() {
        return owner;
    }

    @Override
    public ImageIcon getThumbnail(){
        return thumbnail;
    }

    /**
     * Creates and stores a thumbnail with object information such as path, name
     * and extension
     */
    public void createThumbnail() {
        String uri = path + "/" + name + ".jpg";
        if ((new File(uri).exists())) {
            ImageIcon originalImage = new ImageIcon(uri);
            Image img = originalImage.getImage();
            Image scaledImg = img.getScaledInstance(THUMBHEIGHT, THUMBWIDTH,
                    java.awt.Image.SCALE_SMOOTH);
            this.thumbnail = new ImageIcon(scaledImg);
        } else {
            this.thumbnail = new ImageIcon(getClass().getResource("/broken_link.png"));
        }
    }
}

